package com.changgou.order.listener;

import com.changgou.order.service.PreferentialService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Project: com.changgou.order.listener
 * @Author: ShaoDi Wang
 * @Date: Created in 2019-08-06 21:03
 * @Description:
 * @Version: 1.0
 */
@Component
@RabbitListener(queues = "tb_preferential_update")
public class PreflListener {

    @Autowired
    private PreferentialService preferentialService;

    @Autowired
    private RedisTemplate redisTemplate;

    private final String prefKey="preferential";

    /**
     * 更新优惠金额计算
     * @param message
     */
    @RabbitHandler
    public void updatePref(String message){
        System.out.println("接收到消息:"+message);
        List list = preferentialService.findAll( );
        redisTemplate.boundValueOps( prefKey ).set( list );
    }
}
